package pers.rcl.web;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

import pers.rcl.utils.IdUtils;
import pers.rcl.utils.xx;

public class TestIdController extends Controller {
	/**
	 * 测试生成不重复id
	 */
	public void generateIds() {
		List<Long> list = new ArrayList<>();
		for (int i = 0; i < 10; i++) {
			// 自动生成不重复的id，id的长度不变
			Long id = IdUtils.generateId();
			list.add(id);
		}
		setAttr("ids", list);
		render("/see_ids.html");
	}

	/**
	 * 测试使用JSONObject 作为action参数
	 * 
	 * @param record
	 */
	public void test(JSONObject record) {
		Record user = xx.getUser();
		renderJson(user);
	}

	/**
	 * 查询数据库测试，多数据源进行测试
	 */
	public void findUsers() {
		List<Record> users = Db.find("select * from sys_user");
		List<Record> demoUsers = Db.use("test").find("select * from users");
		setAttr("users", users);
		setAttr("demoUsers", demoUsers);
		render("/WEB-INF/views/test2.html");
	}
}
